package com.corpgovernment.common.passport.context;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/***
 * @author zwmao
 * @version 1.0.0
 * @date 2023/9/4
 **/
@Component
public class PassportSpringContext implements ApplicationContextAware {

    private static ApplicationContext context;

    private static void setContext(ApplicationContext applicationContext) {
        context = applicationContext;
    }

    public static Object getBean(String name){
        return context.getBean(name);
    }

    public static <T> T getBean(Class<T> beanClass) {
        return context.getBean(beanClass);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        setContext(applicationContext);
    }
}
